package com.igeek.javase.list.test;
import java.util.Scanner;
import java.util.LinkedList;
/**
 * @author chenmin
 * 2023/7/17 23:26
 * @description TODO
 * 使用LinkedList，模拟完成堆栈操作  先进后出  push pop
 */
public class StringStack {
    LinkedList<String> ld = new LinkedList<String>();

    public void push(String s) {             //入栈操作
        ld.addFirst(s);
    }

    public String pop() {                   //出栈操作
        return ld.removeFirst();
    }

    public boolean isEmpty() {
        return ld.isEmpty();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringStack stack = new StringStack();
        System.out.println("请输入数据（以quit结束）");
        while (true) {
            String input = sc.next();
            if (input.equals("quit"))
                break;
            stack.push(input);
        }
        System.out.println("先进后出的顺序是：");
        while (!stack.isEmpty())
            System.out.print(stack.pop() + " ");
    }

}

